package com.haoshuang.zhouzhoubang.ui.page.study.child

import com.haoshuang.zhouzhoubang.model.api.ApiRepo
import com.haoshuang.zhouzhoubang.model.bean.TrainArticleBean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.net.ResponseBean
import com.mufeng.libs.net.netRequest
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData


class StudyChildViewModel : BaseViewModel() {

    /**
     * 获取培训文章列表
     */
    val getTrainArticleListData = StatefulMutableLiveData<ResponseBean<MutableList<TrainArticleBean>>>()
    fun getTrainArticleList(type_id: Int, page: Int) = netRequest {
        start { getTrainArticleListData.value = StateData.Loading }
        request { ApiRepo.getTrainArticleList(type_id, page)  }
        success { getTrainArticleListData.value = StateData.Success(it) }
        error { code, msg ->
            getTrainArticleListData.value = StateData.Error(code, msg)
        }
    }

}